<template>
  <!-- 日积分明细 -->
  <div class="wise-integral-detail">
    <van-row style="background: #fff">
      <van-col span="12">
        <div class="login-name">{{ loginName }}（{{ loginId }}）</div>
      </van-col>
      <van-col span="12">
        <date-time v-show="type === 'dayNew'" ref="dataTimeRefdayNew" @date="handleChangeDayNew" />
        <date-time
          v-show="type === 'monthNew'"
          ref="dataTimeRefmonthNew"
          datetype="year-month"
          @date="handleChangeMonthNew"
        />
      </van-col>
    </van-row>
    <integral-pie ref="integralPieRef" />
    <div class="integral-info" v-if="type === 'dayNew'">
      <div class="info-item">
        <div class="title">当日积分</div>
        <div class="value">{{ info.SCO }}</div>
      </div>
      <div class="info-item">
        <div class="title">月累计积分</div>
        <div class="value">{{ info.SCO_M }}</div>
      </div>
    </div>
    <vxe-table
      v-if="type == 'dayNew'"
      size="small"
      border="inner"
      empty-text="没有更多数据了！"
      :tree-config="{ transform: true, rowField: 'KPI_CODE', parentField: 'PARENT_ID' }"
      :data="tableData"
    >
      <vxe-column field="KPI_NAME" title="指标" tree-node></vxe-column>
      <vxe-column field="KPI_VALUE" title="当日值" width="100">
        <template #default="{ row }">
          <span v-if="row.KPI_VALUE == 0 || row.IFMX == 0">{{ row.KPI_VALUE }}</span>
          <span v-else class="color-click" @click="openDetail(`day_${row.KPI_CODE}`)">{{ row.KPI_VALUE }}</span>
        </template>
      </vxe-column>
      <vxe-column field="KPI_VALUE_M" title="月累计" width="100">
        <template #default="{ row }">
          <span v-if="row.KPI_VALUE_M == 0 || row.IFMX == 0">{{ row.KPI_VALUE_M }}</span>
          <span v-else class="color-click" @click="openDetail(`month_${row.KPI_CODE}_M`)">{{ row.KPI_VALUE_M }}</span>
        </template>
      </vxe-column>
    </vxe-table>
    <vxe-table
      v-else
      size="small"
      border="inner"
      empty-text="没有更多数据了！"
      :tree-config="{ transform: true, rowField: 'KPI_CODE', parentField: 'PARENT_ID' }"
      :data="tableData"
    >
      <vxe-column field="KPI_NAME" title="指标" tree-node></vxe-column>
      <vxe-column field="KPI_VALUE" title="当月值" width="100">
        <template #default="{ row }">
          <span v-if="row.KPI_VALUE == 0 || row.IFMX == 0">{{ row.KPI_VALUE }}</span>
          <span v-else class="color-click" @click="openDetail(`month_${row.KPI_CODE}`)">{{ row.KPI_VALUE }}</span>
        </template>
      </vxe-column>
    </vxe-table>
  </div>
</template>

<script>
import dateTime from '@/components/common/dateTime.vue'
import * as dayjs from 'dayjs'
import integralPie from '@/views/components/publicline/wise/pie.vue'

import {
  integralDate,
  integralMonthDate,
  dayPieNew,
  dayKpiNew,
  monthPieNew,
  monthIntegralNew,
} from '@/api/publicline/wise.js'

export default {
  components: { dateTime, integralPie },
  data() {
    return {
      time: '',
      loginId: '',
      loginName: '',
      type: '',
      tableData: [],
      info: {},
      newDayCol: [
        { KPI_NAME: '基础联接积分(计薪酬)', KPI_CODE: 'SCO_JCLJ', IFMX: 0, PARENT_ID: 'TOTAL_SCO' },
        { KPI_NAME: '移网新发展', KPI_CODE: 'SCO_GSM_DEV', IFMX: 1, PARENT_ID: 'SCO_JCLJ' },
        { KPI_NAME: '宽带新发展', KPI_CODE: 'SCO_KD_DEV', IFMX: 1, PARENT_ID: 'SCO_JCLJ' },
        { KPI_NAME: '融合积分', KPI_CODE: 'SCO_COMP', IFMX: 1, PARENT_ID: 'SCO_JCLJ' },
        { KPI_NAME: '固话新发展', KPI_CODE: 'SCO_GH_DEV', IFMX: 1, PARENT_ID: 'SCO_JCLJ' },
        { KPI_NAME: '2I业务交付', KPI_CODE: 'SCO_2I', IFMX: 1, PARENT_ID: 'SCO_JCLJ' },
        { KPI_NAME: '质量追溯', KPI_CODE: 'SCO_CUT_JCLJ', IFMX: 1, PARENT_ID: 'SCO_JCLJ' },
        { KPI_NAME: '基础创新积分', KPI_CODE: 'SCO_JCCX', IFMX: 0, PARENT_ID: 'TOTAL_SCO' },
        { KPI_NAME: '基础组网', KPI_CODE: 'SCO_WJZW_BASE', IFMX: 1, PARENT_ID: 'SCO_JCCX' },
        { KPI_NAME: '超级WIFI(FTTR)', KPI_CODE: 'SCO_WJZW_FTTR', IFMX: 1, PARENT_ID: 'SCO_JCCX' },
        { KPI_NAME: '联通看家', KPI_CODE: 'SCO_WJSY', IFMX: 1, PARENT_ID: 'SCO_JCCX' },
        { KPI_NAME: '联通智能固话', KPI_CODE: 'SCO_WJGH', IFMX: 1, PARENT_ID: 'SCO_JCCX' },
        { KPI_NAME: '联通超清(IPTV基础)', KPI_CODE: 'SCO_IPTV', IFMX: 1, PARENT_ID: 'SCO_JCCX' },
        { KPI_NAME: '联通超清(IPTV增值)', KPI_CODE: 'SCO_TV_INC', IFMX: 1, PARENT_ID: 'SCO_JCCX' },
        { KPI_NAME: '宽视界', KPI_CODE: 'SCO_KSJ', IFMX: 1, PARENT_ID: 'SCO_JCCX' },
        { KPI_NAME: '视频彩铃', KPI_CODE: 'SCO_GZCX_CALL', IFMX: 1, PARENT_ID: 'SCO_JCCX' },
        { KPI_NAME: '联通云盘', KPI_CODE: 'SCO_GZCX_LTYP', IFMX: 1, PARENT_ID: 'SCO_JCCX' },
        { KPI_NAME: '联通助理', KPI_CODE: 'SCO_GZCX_LTZL', IFMX: 1, PARENT_ID: 'SCO_JCCX' },
        { KPI_NAME: '基础创新其他', KPI_CODE: 'SCO_GZCX_OTHER', IFMX: 1, PARENT_ID: 'SCO_JCCX' },
        { KPI_NAME: '质量追溯', KPI_CODE: 'SCO_CUT_JCCX', IFMX: 0, PARENT_ID: 'SCO_JCCX' },
        { KPI_NAME: '行业创新积分', KPI_CODE: 'SCO_HYCX', IFMX: 0, PARENT_ID: 'TOTAL_SCO' },
        { KPI_NAME: '云计算', KPI_CODE: 'SCO_GYY', IFMX: 1, PARENT_ID: 'SCO_HYCX' },
        { KPI_NAME: '大数据标准产品', KPI_CODE: 'SCO_BIGDATA', IFMX: 1, PARENT_ID: 'SCO_HYCX' },
        { KPI_NAME: '物联网连接类', KPI_CODE: 'SCO_WLW', IFMX: 1, PARENT_ID: 'SCO_HYCX' },
        { KPI_NAME: '商务云快线', KPI_CODE: 'SCO_YUNKX', IFMX: 0, PARENT_ID: 'SCO_HYCX' },
        { KPI_NAME: '数字乡村', KPI_CODE: 'SCO_SZXC', IFMX: 0, PARENT_ID: 'SCO_HYCX' },
        { KPI_NAME: '双线', KPI_CODE: 'SCO_SX', IFMX: 1, PARENT_ID: 'SCO_HYCX' },
        { KPI_NAME: 'IDC/EDC项目', KPI_CODE: 'SCO_IDC', IFMX: 1, PARENT_ID: 'SCO_HYCX' },
        { KPI_NAME: 'ICT', KPI_CODE: 'SCO_ICT', IFMX: 0, PARENT_ID: 'SCO_HYCX' },
        { KPI_NAME: '本地行业云池(新兴ICT)', KPI_CODE: 'SCO_YUN', IFMX: 0, PARENT_ID: 'SCO_HYCX' },
        { KPI_NAME: '物联网非连接(新兴ICT)', KPI_CODE: 'SCO_ICT_WLW', IFMX: 0, PARENT_ID: 'SCO_HYCX' },
        { KPI_NAME: '大数据(新兴ICT)', KPI_CODE: 'SCO_ICT_BIGDATA', IFMX: 0, PARENT_ID: 'SCO_HYCX' },
        { KPI_NAME: '价值运营积分', KPI_CODE: 'SCO_JZYY', IFMX: 0, PARENT_ID: 'TOTAL_SCO' },
        { KPI_NAME: '5G升级包', KPI_CODE: 'SCO_GSM_SJB', IFMX: 1, PARENT_ID: 'SCO_JZYY' },
        { KPI_NAME: '套餐升档提值', KPI_CODE: 'SCO_VALUE_UP', IFMX: 1, PARENT_ID: 'SCO_JZYY' },
        { KPI_NAME: '宽带提速包', KPI_CODE: 'SCO_KD_TS', IFMX: 1, PARENT_ID: 'SCO_JZYY' },
        { KPI_NAME: '宽带续约', KPI_CODE: 'SCO_KD_XY', IFMX: 1, PARENT_ID: 'SCO_JZYY' },
        { KPI_NAME: '终端销售', KPI_CODE: 'SCO_SALE', IFMX: 1, PARENT_ID: 'SCO_JZYY' },
        { KPI_NAME: '质量追溯', KPI_CODE: 'SCO_CUT_JZYY', IFMX: 1, PARENT_ID: 'SCO_JZYY' },
        { KPI_NAME: '交付积分(计薪酬)', KPI_CODE: 'SCO_FWWHJF', IFMX: 0, PARENT_ID: 'TOTAL_SCO' },
        { KPI_NAME: '装机', KPI_CODE: 'SCO_ZJ', IFMX: 1, PARENT_ID: 'SCO_FWWHJF' },
        { KPI_NAME: '联通看家(华盛)-室内', KPI_CODE: 'SCO_ZJ_WJSY_SN', IFMX: 0, PARENT_ID: 'SCO_FWWHJF' },
        { KPI_NAME: '联通看家(华盛)-室外', KPI_CODE: 'SCO_ZJ_WJSY_SW', IFMX: 0, PARENT_ID: 'SCO_FWWHJF' },
        { KPI_NAME: '联通看家(系统)', KPI_CODE: 'SCO_DYPP', IFMX: 1, PARENT_ID: 'SCO_FWWHJF' },
        { KPI_NAME: '联通组网', KPI_CODE: 'SCO_ZJ_WJZW', IFMX: 1, PARENT_ID: 'SCO_FWWHJF' },
        { KPI_NAME: '换猫积分(不计薪酬)', KPI_CODE: 'SCO_HM', IFMX: 1, PARENT_ID: 'SCO_FWWHJF' },
        { KPI_NAME: '质量追溯', KPI_CODE: 'SCO_CUT_FWWHJF', IFMX: 1, PARENT_ID: 'SCO_FWWHJF' },
        { KPI_NAME: '追溯积分', KPI_CODE: 'SCO_CUT', IFMX: 0, PARENT_ID: 'TOTAL_SCO' },
      ],
      newCol: [
        { KPI_NAME: '基础联接积分(计薪酬)', IFMX: 0, PARENT_ID: 'TOTAL_SCO', KPI_CODE: 'NEW_DEV_SAL_JF' },
        { KPI_NAME: '移网新发展', IFMX: 1, PARENT_ID: 'NEW_DEV_SAL_JF', KPI_CODE: 'SCO_GSM_DEV' },
        { KPI_NAME: '宽带新发展', IFMX: 1, PARENT_ID: 'NEW_DEV_SAL_JF', KPI_CODE: 'SCO_KD_DEV' },
        { KPI_NAME: '融合积分', IFMX: 1, PARENT_ID: 'NEW_DEV_SAL_JF', KPI_CODE: 'SCO_COMP' },
        { KPI_NAME: '固话新发展', IFMX: 1, PARENT_ID: 'NEW_DEV_SAL_JF', KPI_CODE: 'SCO_GH_DEV' },
        { KPI_NAME: '2I业务交付', IFMX: 1, PARENT_ID: 'NEW_DEV_SAL_JF', KPI_CODE: 'SCO_2I' },
        { KPI_NAME: '质量追溯', IFMX: 1, PARENT_ID: 'NEW_DEV_SAL_JF', KPI_CODE: 'SCO_CUT_DEV' },
        { KPI_NAME: '基础创新积分', IFMX: 0, PARENT_ID: 'TOTAL_SCO', KPI_CODE: 'SCO_JCCX' },
        { KPI_NAME: '基础组网', IFMX: 1, PARENT_ID: 'SCO_JCCX', KPI_CODE: 'SCO_WJZW_BASE' },
        { KPI_NAME: '超级WIFI(FTTR)', IFMX: 1, PARENT_ID: 'SCO_JCCX', KPI_CODE: 'SCO_WJZW_FTTR' },
        { KPI_NAME: '联通看家', IFMX: 1, PARENT_ID: 'SCO_JCCX', KPI_CODE: 'SCO_WJSY' },
        { KPI_NAME: '联通智能固话', IFMX: 1, PARENT_ID: 'SCO_JCCX', KPI_CODE: 'SCO_WJGH' },
        { KPI_NAME: '联通超清(IPTV基础)', IFMX: 1, PARENT_ID: 'SCO_JCCX', KPI_CODE: 'SCO_IPTV' },
        { KPI_NAME: '联通超清(IPTV增值)', IFMX: 1, PARENT_ID: 'SCO_JCCX', KPI_CODE: 'SCO_GZCX_TV' },
        { KPI_NAME: '宽视界', IFMX: 1, PARENT_ID: 'SCO_JCCX', KPI_CODE: 'SCO_KSJ' },
        { KPI_NAME: '视频彩铃', IFMX: 1, PARENT_ID: 'SCO_JCCX', KPI_CODE: 'SCO_GZCX_CALL' },
        { KPI_NAME: '联通云盘', IFMX: 1, PARENT_ID: 'SCO_JCCX', KPI_CODE: 'SCO_GZCX_LTYP' },
        { KPI_NAME: '联通助理', IFMX: 1, PARENT_ID: 'SCO_JCCX', KPI_CODE: 'SCO_GZCX_LTZL' },
        { KPI_NAME: '基础创新其他', IFMX: 1, PARENT_ID: 'SCO_JCCX', KPI_CODE: 'SCO_GZCX_OTHER' },
        { KPI_NAME: '质量追溯', IFMX: 1, PARENT_ID: 'SCO_JCCX', KPI_CODE: 'SCO_JCCX_CUT' },
        { KPI_NAME: '行业创新积分', IFMX: 0, PARENT_ID: 'TOTAL_SCO', KPI_CODE: 'SCO_HYCX' },
        { KPI_NAME: '云计算', IFMX: 0, PARENT_ID: 'SCO_HYCX', KPI_CODE: 'SCO_GYY' },
        { KPI_NAME: '大数据标准产品', IFMX: 1, PARENT_ID: 'SCO_HYCX', KPI_CODE: 'SCO_BIGDATA' },
        { KPI_NAME: '物联网连接类', IFMX: 1, PARENT_ID: 'SCO_HYCX', KPI_CODE: 'SCO_WLW' },
        { KPI_NAME: '商务云快线', IFMX: 0, PARENT_ID: 'SCO_HYCX', KPI_CODE: 'SCO_YUNKX' },
        { KPI_NAME: '数字乡村', IFMX: 0, PARENT_ID: 'SCO_HYCX', KPI_CODE: 'SCO_SZXC' },
        { KPI_NAME: '双线', IFMX: 1, PARENT_ID: 'SCO_HYCX', KPI_CODE: 'SCO_SX' },
        { KPI_NAME: 'IDC/EDC项目', IFMX: 1, PARENT_ID: 'SCO_HYCX', KPI_CODE: 'SCO_IDC' },
        { KPI_NAME: 'ICT', IFMX: 1, PARENT_ID: 'SCO_HYCX', KPI_CODE: 'SCO_ICT' },
        { KPI_NAME: '本地行业云池(新兴ICT)', IFMX: 1, PARENT_ID: 'SCO_HYCX', KPI_CODE: 'SCO_YUN' },
        { KPI_NAME: '物联网非连接(新兴ICT)', IFMX: 1, PARENT_ID: 'SCO_HYCX', KPI_CODE: 'SCO_ICT_WLW' },
        { KPI_NAME: '大数据(新兴ICT)', IFMX: 1, PARENT_ID: 'SCO_HYCX', KPI_CODE: 'SCO_ICT_BIGDATA' },
        { KPI_NAME: '价值运营', IFMX: 0, PARENT_ID: 'TOTAL_SCO', KPI_CODE: 'CLWX_SAL_JF' },
        { KPI_NAME: '5G升级包', IFMX: 1, PARENT_ID: 'CLWX_SAL_JF', KPI_CODE: 'SCO_GSM_SJB' },
        { KPI_NAME: '套餐升档提值', IFMX: 1, PARENT_ID: 'CLWX_SAL_JF', KPI_CODE: 'SCO_VALUE_UP' },
        { KPI_NAME: '宽带提速包', IFMX: 1, PARENT_ID: 'CLWX_SAL_JF', KPI_CODE: 'SCO_KD_TS' },
        { KPI_NAME: '宽带续约', IFMX: 1, PARENT_ID: 'CLWX_SAL_JF', KPI_CODE: 'SCO_KD_XY' },
        { KPI_NAME: '终端销售', IFMX: 1, PARENT_ID: 'CLWX_SAL_JF', KPI_CODE: 'SCO_SALE' },
        { KPI_NAME: '质量追溯', IFMX: 1, PARENT_ID: 'CLWX_SAL_JF', KPI_CODE: 'SCO_CUT_CLWX' },
        { KPI_NAME: '交付积分(计薪酬)', IFMX: 0, PARENT_ID: 'TOTAL_SCO', KPI_CODE: 'FWWHJF' },
        { KPI_NAME: '装机', IFMX: 1, PARENT_ID: 'FWWHJF', KPI_CODE: 'SCO_ZJ' },
        { KPI_NAME: '联通看家(华盛)-室内', IFMX: 0, PARENT_ID: 'FWWHJF', KPI_CODE: 'SCO_ZJ_WJSY_SN' },
        { KPI_NAME: '联通看家(华盛)-室外', IFMX: 0, PARENT_ID: 'FWWHJF', KPI_CODE: 'SCO_ZJ_WJSY_SW' },
        { KPI_NAME: '联通看家(系统)', IFMX: 1, PARENT_ID: 'FWWHJF', KPI_CODE: 'SCO_DYPP' },
        { KPI_NAME: '联通组网', IFMX: 1, PARENT_ID: 'FWWHJF', KPI_CODE: 'SCO_ZJ_WJZW' },
        { KPI_NAME: '换猫积分(不计薪酬)', IFMX: 1, PARENT_ID: 'FWWHJF', KPI_CODE: 'SCO_WXXF' },
        { KPI_NAME: '质量追溯', IFMX: 1, PARENT_ID: 'FWWHJF', KPI_CODE: 'SCO_CUT_JF' },
        { KPI_NAME: '追溯积分', IFMX: 0, PARENT_ID: 'TOTAL_SCO', KPI_CODE: 'SCO_CUT' },
      ],
    }
  },
  created() {
    this.time = this.$route.query.time
    this.loginId = this.$route.query.loginId
    this.loginName = this.$route.query.loginName
    this.type = this.$route.query.type
  },
  mounted() {
    if (this.type === 'dayNew') {
      this.getAccountDateNew()
      this.getDayPieNew()
      this.getDayKpiNew()
    } else if (this.type === 'monthNew') {
      this.getAccountMonthDateNew()
      this.getMonthPieNew()
      this.getMonthKpiNew()
    }
  },
  methods: {
    // 获取日账期
    async getAccountDateNew() {
      const res = await integralDate({ PARAMCODE: 'D' })
      const { result, success } = res
      if (success) {
        this.$refs.dataTimeRefdayNew.initDateTime(
          dayjs(this.time).format('YYYY-MM-DD'),
          dayjs(result[0].value).format('YYYY-MM-DD')
        )
      }
    },
    // 获取月账期
    async getAccountMonthDateNew() {
      const res = await integralMonthDate({ gridId: this.$gridId })
      const { result, success } = res
      if (success) {
        this.$refs.dataTimeRefmonthNew.initDateTime(
          dayjs(this.time).format('YYYY-MM'),
          dayjs(result[0].value).format('YYYY-MM')
        )
      }
    },
    handleChangeDayNew(val) {
      this.time = dayjs(val).format('YYYYMMDD')
      this.getDayPieNew()
      this.getDayKpiNew()
    },
    handleChangeMonthNew(val) {
      this.time = dayjs(val).format('YYYYMM')
      this.getMonthPieNew()
      this.getMonthKpiNew()
    },
    async getDayPieNew() {
      const res = await dayPieNew({ loginId: this.loginId, dayId: this.time })
      const { result, success } = res
      if (success) {
        this.info = result[0] || {}
        const data = [
          { value: this.info.SCO_JCLJ || 0, name: '基础联接(计薪酬)' },
          { value: this.info.SCO_JCCX || 0, name: '基础创新' },
          { value: this.info.SCO_HYCX || 0, name: '行业创新' },
          { value: this.info.SCO_JZYY || 0, name: '价值运营' },
          { value: this.info.SCO_FWWHJF || 0, name: '交付积分(计薪酬)' },
          { value: this.info.SCO_CUT || 0, name: '追溯积分' },
        ]
        this.$refs.integralPieRef.initPie(this.info.SCO || 0, data, '积分')
      }
    },
    async getDayKpiNew() {
      const res = await dayKpiNew({ loginId: this.loginId, dayId: this.time })
      const { result, success } = res
      if (success) {
        const list = result
        if (list.length != 0) {
          const info = result[0]
          this.newDayCol.forEach((item) => {
            item.KPI_VALUE = info[item.KPI_CODE]
            item.KPI_VALUE_M = info[`${item.KPI_CODE}_M`]
          })
          this.tableData = this.newDayCol
        } else {
          this.tableData = []
        }
      }
    },
    async getMonthPieNew() {
      const res = await monthPieNew({ loginId: this.loginId, monthId: this.time })
      const { result, success } = res
      if (success) {
        const info = result[0] || {}
        const data = [
          { value: info.NEW_DEV_SAL_JF || 0, name: '基础联接(计薪酬)' },
          { value: info.SCO_JCCX || 0, name: '基础创新' },
          { value: info.SCO_HYCX || 0, name: '行业创新' },
          { value: info.CLWX_SAL_JF || 0, name: '存量维系' },
          { value: info.FWWHJF || 0, name: '交付积分(计薪酬)' },
          { value: info.SCO_CUT || 0, name: '追溯积分' },
        ]
        this.$refs.integralPieRef.initPie(info.TOTAL_SCO || 0, data, '积分')
      }
    },
    async getMonthKpiNew() {
      const res = await monthIntegralNew({ loginId: this.loginId, monthId: this.time })
      const { result, success } = res
      if (success) {
        const list = result.list
        if (list.length != 0) {
          const info = result.list[0]
          this.newCol.forEach((item) => {
            item.KPI_VALUE = info[item.KPI_CODE]
          })
          this.tableData = this.newCol
        } else {
          this.tableData = []
        }
      }
    },
    openDetail(jfType) {
      this.$open.call(this, '/publicline/wise/integralDetailNew', {
        jfType,
        loginId: this.loginId,
        time: this.time,
      })
    },
  },
}
</script>
<style lang="less" scoped>
.wise-integral-detail {
  .login-name {
    padding: 12px 16px;
  }
  .charts {
    background: #fff;
  }
  .integral-info {
    background: #fff;
    padding: 0 16px;
    margin-bottom: 10px;
    .info-item {
      width: 50%;
      text-align: center;
      background-image: url('~@/assets/imgs/publicline/board/bg-card-fz.png');
      background-repeat: no-repeat;
      background-size: 100% 100%;
      padding: 16px 0;
      display: inline-block;
      margin-top: 12px;
      margin-bottom: 6px;
    }
    .value {
      font-size: 24px;
      color: #4d98ff;
      margin-top: 3px;
      margin-bottom: 6px;
    }
  }
  // 表格第一列表头设置
  .vxe-table /deep/ .vxe-table--header th:first-child .vxe-cell {
    padding-left: 44px;
  }
  .color-click {
    color: #4d98ff;
    text-decoration: underline;
  }
}
</style>
